home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / admin / usage < prev    next >
Encoding:
Text File  |  1997-08-26  |  3.0 KB  |  109 lines

  1. #!/bin/sh
  2. # *** NOTE!!! ***
  3. # This is one of three programs you will need to implement advisory quotas.
  4. # There is also a related utility to actually pare down users' usage.
  5. # The complete set consists of quota, usage, pareacct, and gawk (quota is
  6. # written in gawk; it requires gawk to interpret/run it).
  7. # The URLs to retrieve these are:
  8. # ftp://ftp.armory.com/pub/admin/quota
  9. # ftp://ftp.armory.com/pub/admin/usage
  10. # ftp://ftp.armory.com/pub/admin/pareacct
  11. # ftp://ftp.armory.com/pub/scobins/gawk (binary for SCO UNIX 3.2v5)
  12.  
  13. # @(#) usage.sh 2.1 97/04/19
  14. # 94/03/03 john h. dubois iii (john@armory.com)
  15. # 94/06/15 Generalized
  16. # 94/07/10 Do only one 'mount' for all fs
  17. # 94/07/11 Put date at start of file
  18. # 95/07/02 Record inodes used
  19. # 96/03/11 Use gawk to write date as epoch time so that quota can format it.
  20. # 97/04/19 Make gawk test work right.
  21.  
  22. # Update usage file for use by quota.
  23.  
  24. # Usage: fs-device [mountdir fs-device ...]
  25. MkDB() {
  26.     quot=/usr/bin/quot
  27.     Dir=
  28.     case "$1" in
  29.     /*) fs="$1";;
  30.     *) fs="/dev/$1";;    # Add leading /dev if needed.
  31.     esac
  32.     shift
  33.     if [ ! -b "$fs" ]; then
  34.     echo "$0: $fs does not exist or is not a block device."
  35.     return 1
  36.     fi
  37.     while [ $# -gt 0 ]; do
  38.     if [ "$fs" = "$2" ]; then
  39.         Dir=$1
  40.         break
  41.     fi
  42.     shift; shift
  43.     done
  44.     if [ -z "$Dir" ]; then
  45.     # Print this only if output is a terminal,
  46.     # to avoid needless mail from cron.
  47.     test -t && echo "$0: Filesystem $fs is not mounted."
  48.     return 1
  49.     fi
  50.     file="$Dir/Usage"
  51.     new=$file+
  52.     echo "$Date" > $new
  53.     # Discard error output unless quot fails,
  54.     # because new quot whines about duplicate UIDs.
  55.     ErrOut="`$quot $f "$fs" 2>&1 >> $new`" || echo "$ErrOut"
  56.     # If mv fails, only print an error message if the new file still exists.
  57.     # If it doesn't, mv failed because cron double-executed this job, creating
  58.     # a race state; the other job moved it before this one could.
  59.     mv "$new" "$file" 2>/dev/null || {
  60.     if [ -f "$new" ]; then
  61.         echo "$0: Failed to move '$new' to '$file'"
  62.         l "$new" "$file"
  63.     fi
  64.     }
  65. }
  66.  
  67. if [ "$1" = -h ]; then
  68.     echo \
  69. "$0: Build filesystem usage database for the 'quota' program.
  70. Usage: $0 [-h] filesystem-device ...
  71. For each filesystem device named, a usage database is written into a
  72. file named Usage in the directory the filesystem is mounted on.
  73. This command is typically run from root's crontab at regular intervals.
  74. Example: $0 /dev/u /dev/v"
  75.     exit 0
  76. fi
  77.  
  78. if [ $# -eq 0 ]; then
  79.     echo "$0: No device names given.  Use -h for help."
  80.     exit 1
  81. fi
  82.  
  83. Filesystems="$*"
  84. OIFS=$IFS
  85. IFS='
  86. '
  87. set -- `/etc/mount`
  88. IFS=$OIFS
  89. f=-f    # Record inodes used also; comment this out if inode quotas not used
  90.  
  91. PATH=$PATH:/usr/local/bin
  92. Date=`(gawk '
  93. BEGIN {
  94.     printf "%s (%s)\n",systime(),strftime("%a %b %d %H:%M")
  95. }
  96. ') 2>/dev/null` || Date=`date '+%a %b %d %H:%M'`
  97. for fs
  98. do
  99.     set -- $fs
  100.     # This needs to be changed if using xenix 'mount' cmd
  101.     DevList="$DevList $1 $3"
  102. done
  103.  
  104. umask 022    # let everyone read the usage file
  105. for fs in $Filesystems
  106. do
  107.     MkDB "$fs" $DevList
  108. done
  109.